
#include <BFont>
#include <BWidget>
#include "member_BTimeEdit.h"

using namespace BWE;

member_BTimeEdit::member_BTimeEdit(BTimeEdit* timeEdit)
{
	boss = timeEdit;
	readOnly = false;
	edited = false;
	pressed = false;
	synchro = false;
	align = Align_Center;
	format.reset("hh:mm:ss");
	blinkTick = 0.0;
	blinkTime = 1.0;
	blinkShown = false;

	dirty = true;
	textHeight = 0;
	dirtyText = true;
	hoverIndex = 0;
	inputIndex = 0;
	inputCount = 0;
}
member_BTimeEdit::~member_BTimeEdit()
{

}


void member_BTimeEdit::freshRects()
{
	const BStyle* style = boss->realStyle();
	const BFont* font = boss->font();
	if (!font)
		return;

	BRect centerRect = boss->centerRect();

	BSize textSize = font->textSize(format);
	textRect = centerRect.align(align, textSize);

	int count = text.count();
	rects.resize(count + 1);

	int tx = textRect.x();
	int ty = textRect.y();
	int th = textRect.height();
	for (auto cit = text.begin(); cit != text.end(); cit++)
	{
		int tw = font->codeWidth(cit.code());
		rects[cit.count()].set(tx, ty, tw, th);
		tx += tw;
	}
	rects.last().set(tx, ty, th, th);

	if (inputIndex < 0)
		inputIndex = 0;
	if (inputIndex > count)
		inputIndex = count;
	if (inputIndex + inputCount >= count)
	{
		inputCount = count - inputIndex;
	}
}
